home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Tele / Pete Johnson / FC LogScan 1.0.2<source>.cpt / Configure.p next >
Encoding:
Text File  |  1992-03-04  |  13.5 KB  |  458 lines  |  [TEXT/PJMM]

  1. unit Configure;
  2.  
  3. interface
  4.  
  5.     uses
  6.         Globals, StringFunctions, TextUtils;
  7.  
  8.     procedure FrameDItem (dLog: DialogPtr; iNum: integer);
  9.     function ButtonSelected (whichDialog: DialogPtr; whichItem: integer): boolean;
  10.     procedure ReadDefaults;
  11.     procedure WriteResources (Defaults: Settings);
  12.     function Configure (var newDefaults: Settings): boolean;
  13.  
  14. implementation
  15.  
  16. {-----------------------------------------------------------------    }
  17.  
  18.     procedure FrameDItem; {(dLog: DialogPtr; iNum: integer)}
  19.  
  20.         var
  21.             iBox: Rect;
  22.             iType: integer;
  23.             iHandle: Handle;
  24.             oldPenState: PenState;
  25.  
  26.     begin
  27.         GetPenState(oldPenState);
  28.         GetDItem(dLog, iNum, iType, iHandle, iBox);
  29.         InsetRect(iBox, -4, -4);
  30.         PenSize(3, 3);
  31.         FrameRoundRect(iBox, 16, 16);
  32.         SetPenState(oldPenState)
  33.     end;
  34.  
  35. {-----------------------------------------------------------------    }
  36.  
  37.     function ButtonSelected; {(whichDialog: DialogPtr; whichItem: integer): boolean;}
  38.  
  39.         var
  40.             whichType: integer;
  41.             whichHandle: handle;
  42.             whichRect, displayRect: rect;
  43.             mouseLoc: point;
  44.             DelayTime: longint;
  45.             nowInverted: boolean;
  46.  
  47.     begin
  48.         getDItem(whichDialog, whichItem, whichType, whichHandle, whichRect);
  49.         displayRect := whichRect;
  50.         InsetRect(displayRect, 1, 1);
  51.         InvertRect(displayRect);
  52.         nowInverted := true;
  53.         if StillDown then
  54.             repeat
  55.                 GetMouse(mouseLoc);
  56.                 if PtInRect(mouseLoc, whichRect) then
  57.                     begin
  58.                         if not nowInverted then
  59.                             begin
  60.                                 InvertRect(displayRect);
  61.                                 nowInverted := true
  62.                             end
  63.                     end
  64.                 else
  65.                     begin
  66.                         if nowInverted then
  67.                             begin
  68.                                 InvertRect(displayRect);
  69.                                 nowInverted := false
  70.                             end
  71.                     end
  72.             until not StillDown;
  73.         if nowInverted then
  74.             begin
  75.                 Delay(4, DelayTime);
  76.                 InvertRect(displayRect);
  77.             end;
  78.         ButtonSelected := nowInverted
  79.     end;
  80.  
  81. {-----------------------------------------------------------------    }
  82.  
  83.     procedure ReadDefaults;
  84.  
  85. {    _________Resource_notes__________                                                                }
  86. {    STR# 128 holds report settings as follows:                                                            }
  87. {        #1        two-character string with Call symbol and NoCall symbol                                }
  88. {        #2        title string: BBS activity from ^0 to ^1                                                    }
  89. {        #3        summary: ^0 Graphic Interface calls, ^1 Command Line Interface calls, ^2 total        }
  90. {        #4         Header file name                                                                                }
  91. {        #5        "Line"                                                                                            }
  92. {        #6        "time used"                                                                                    }
  93. {        #7        "Connection speeds"                                                                            }
  94. {        #8        "Registrations"                                                                                }
  95. {        #9        "Name                     Calls  Time"                                                            }
  96. {        #10    "Total"                                                                                        }
  97. {        #11    Sessions to omit, comma separated                                                            }
  98. {                Can contain up to 10 session numbers                                                        }
  99. {        #12    TEXT file signature                                                                            }
  100. {    STR# 129 holds log prompts as follows:                                                                }
  101. {        #1        " Start "                                                                                        }
  102. {        #2        " Command Line "                                                                                }
  103. {        #3        " Session Ended. "                                                                            }
  104. {        #4        " auto-registered Sess "                                                                        }
  105. {    STR# 130 holds paths & misc info as follows:                                                            }
  106. {        #1        Path to FC daily logs                                                                            }
  107. {        #2        Path of brief report file                                                                        }
  108. {        #3        Name of brief report file                                                                        }
  109. {        #4        Defaults [1] = MultiFinder, [2] = Automatic, [3] = Big Report, [4] = Brief Report        }
  110. {        #5        Special line to track                                                                            }
  111.  
  112.         var
  113.             tempString, numString: str255;
  114.             Err: OSErr;
  115.             HeaderRef, counter: integer;
  116.             HowManyChars, tempLong: longint;
  117.  
  118.     begin
  119.         GetIndString(tempString, 128, 1);
  120.         callSymbol := tempString[1];
  121.         noCallSymbol := tempString[2];
  122.         GetIndString(TitleString, 128, 2);
  123.         GetIndString(SummaryString, 128, 3);
  124.         GetIndString(HeaderFileName, 128, 4);
  125.         Err := FSOpen(HeaderFileName, vRefNum, HeaderRef);
  126.         if Err = NoErr then
  127.             Err := GetEOF(HeaderRef, HowManyChars);
  128.         if Err = NoErr then
  129.             begin
  130.                 if (HowManyChars > 255) then
  131.                     HowManyChars := 255;
  132.                 Err := FSRead(HeaderRef, HowManyChars, Pointer(ord(@LegendString) + 1));
  133.                 LegendString[0] := char(HowManyChars)
  134.             end
  135.         else
  136.             LegendString := '';
  137.         Err := FSClose(HeaderRef);
  138.         GetIndString(LineTitle, 128, 5);
  139.         GetIndString(TimeUsedTitle, 128, 6);
  140.         GetIndString(ConnectionSpeedsTitle, 128, 7);
  141.         GetIndString(RegistrationsTitle, 128, 8);
  142.         GetIndString(NameCallsTimeTitle, 128, 9);
  143.         GetIndString(TotalTitle, 128, 10);
  144.         GetIndString(tempString, 128, 11);
  145.         HowManyOmits := 0;
  146.         for counter := 1 to IGNORES do
  147.             Defaults.IgnoreSess[counter] := -1;
  148.         while pos(',', tempString) > 0 do
  149.             begin
  150.                 numString := copy(tempString, 1, pos(',', tempString) - 1);
  151.                 HowManyOmits := succ(HowManyOmits);
  152.                 Defaults.IgnoreSess[HowManyOmits] := GetValue(numString);
  153.                 tempString := copy(tempString, pos(',', tempString) + 1, 255);
  154.             end;
  155.         if tempString <> '' then
  156.             begin
  157.                 HowManyOmits := succ(HowManyOmits);
  158.                 Defaults.IgnoreSess[HowManyOmits] := GetValue(tempString)
  159.             end;
  160.         GetIndString(tempString, 128, 12);
  161.         Defaults.Creator := copy(tempString, 1, 4);
  162.         GetIndString(gSessStart, 129, 1);
  163.         GetIndString(gCommandLine, 129, 2);
  164.         GetIndString(gSessionEnd, 129, 3);
  165.         GetIndString(gAutoRegister, 129, 4);
  166.         GetIndString(Defaults.FCLogPath, 130, 1);
  167.         GetIndString(Defaults.BriefPath, 130, 2);
  168.         GetIndString(Defaults.BriefName, 130, 3);
  169.         GetIndString(tempString, 130, 4);
  170.         if tempString[1] = 'Y' then
  171.             Defaults.MFinder := true
  172.         else
  173.             Defaults.MFinder := false;
  174.         if tempString[2] = 'Y' then
  175.             Defaults.Automatic := true
  176.         else
  177.             Defaults.Automatic := false;
  178.         if tempString[3] = 'Y' then
  179.             Defaults.DoBriefRept := true
  180.         else
  181.             Defaults.DoBriefRept := false;
  182.         GetIndString(tempString, 130, 5);
  183.         StringToNum(tempString, tempLong);
  184.         Defaults.SpecialSess := integer(tempLong);
  185.     end;
  186.  
  187. {-----------------------------------------------------------------    }
  188.  
  189.     procedure ToggleButton (var State: boolean; theDialog: DialogPtr; ItemHit: integer);
  190.  
  191.         var
  192.             itemType: integer;
  193.             itemHandle: handle;
  194.             dispRect: rect;
  195.             thisButton: ControlHandle;
  196.  
  197.     begin
  198.         State := not State;
  199.         getDItem(theDialog, ItemHit, itemType, itemHandle, dispRect);
  200.         thisButton := ControlHandle(itemHandle);
  201.         if State then
  202.             SetCtlValue(thisButton, 1)
  203.         else
  204.             SetCtlValue(thisButton, 0)
  205.     end;
  206.  
  207. {-----------------------------------------------------------------    }
  208.  
  209.     procedure MakePath (FName: STR255; VRefNum: integer; var MyPath: STR255);
  210.  
  211.         var
  212.             MyPB: CInfoPBRec;
  213.             Err: OSErr;
  214.  
  215.     begin
  216.         MyPath := '';
  217.         MyPB.ioCompletion := nil;
  218.         MyPB.ioNamePtr := @FName;
  219.         MyPB.ioVRefNum := VRefNum;
  220.         MyPB.ioFDirIndex := 0;
  221.         MyPB.ioDirID := 0;
  222.         Err := PBGetCatInfo(@MyPB, false);
  223.         MyPB.ioFDirIndex := -1;
  224.         MyPB.ioDirID := MyPB.ioDRParID;
  225.         while PBGetCatInfo(@MyPB, false) = NoErr do
  226.             begin
  227.                 MyPath := concat(MyPB.ioNamePtr^, ':', MyPath);
  228.                 MyPB.ioDirID := MyPB.ioDRParID;
  229.                 MyPB.ioFDirIndex := -1;
  230.             end;        {    while PBGetCatInfo(@MyPB, false) = NoErr    }
  231.     end;
  232.  
  233. { ------------------------------------------------------ }
  234.  
  235.     procedure WriteResources; {(Defaults: Settings)}
  236.  
  237. {    STR# 128 holds report settings as follows:                                                            }
  238. {        #11    Sessions to omit, comma separated                                                            }
  239. {                Can contain up to 10 session numbers                                                        }
  240. {        #12    TEXT file signature                                                                            }
  241. {    STR# 130 holds paths & misc info as follows:                                                            }
  242. {        #1        Path to FC daily logs                                                                            }
  243. {        #2        Path of brief report file                                                                        }
  244. {        #3        Name of brief report file                                                                        }
  245. {        #4        Defaults [1] = MultiFinder, [2] = Automatic, [3] = Big Report, [4] = Brief Report        }
  246.  
  247.         var
  248.             Err: OSErr;
  249.             tempString: str255;
  250.             count: integer;
  251.  
  252.     begin
  253.         Err := SetIndString(130, 1, Defaults.FCLogPath);
  254.         Err := SetIndString(130, 2, Defaults.BriefPath);
  255.         Err := SetIndString(130, 3, Defaults.BriefName);
  256.         tempString := 'YYY';
  257.         if not Defaults.MFinder then
  258.             tempString[1] := 'N';
  259.         if not Defaults.Automatic then
  260.             tempString[2] := 'N';
  261.         if not Defaults.DoBriefRept then
  262.             tempString[3] := 'N';
  263.         Err := SetIndString(130, 4, tempString);
  264.         tempString := '';
  265.         for count := 1 to 12 do
  266.             if (Defaults.IgnoreSess[count] > 0) then
  267.                 tempString := concat(tempString, ValueToString(Defaults.IgnoreSess[count]), ',')
  268.             else if (Defaults.IgnoreSess[count] = 0) then
  269.                 tempString := concat(tempString, '0,');
  270.         if tempString[length(tempString)] = ',' then
  271.             tempString := copy(tempString, 1, length(tempString) - 1);
  272.         Err := SetIndString(130, 5, StringOf(Defaults.SpecialSess : 0));
  273.         Err := SetIndString(128, 11, tempString);
  274.         Err := SetIndString(128, 12, Defaults.Creator);
  275.         UpdateResFile(CurResFile)
  276.     end;
  277.  
  278. { ------------------------------------------------------ }
  279.  
  280.     function Configure; {(var newDefaults: Settings): boolean}
  281.  
  282.         var
  283.             ItemHit, itemType, whichItem, count: integer;
  284.             tempString, Location: str255;
  285.             itemHandle: Handle;
  286.             dispRect: Rect;
  287.             thisButton: ControlHandle;
  288.             where: point;
  289.             fileReply: SFReply;
  290.             whatToFind: SFTypeList;
  291.             theDialog: DialogPtr;
  292.             Err: OSErr;
  293.             tempLong: longint;
  294.  
  295.         procedure FlashButton (WhichButton: integer);
  296.  
  297.             var
  298.                 DelayTime: longint;
  299.  
  300.         begin
  301.             getDItem(theDialog, WhichButton, itemType, itemHandle, dispRect);
  302.             InsetRect(dispRect, 1, 1);
  303.             InvertRect(dispRect);
  304.             if StillDown then
  305.                 repeat
  306.                 until not Button
  307.             else
  308.                 Delay(4, DelayTime);
  309.             Delay(4, DelayTime)
  310.         end;
  311.  
  312.     begin
  313.         Configure := false;
  314.         InitCursor;
  315.         ParamText(VERSION, '', '', '');
  316.         theDialog := GetNewDialog(500, nil, POINTER(-1));
  317.         SetPort(theDialog);
  318.         FrameDItem(theDialog, Ok);
  319.  
  320.         getDItem(theDialog, 3, itemType, itemHandle, dispRect);
  321.         SetIText(itemHandle, newDefaults.FCLogPath);
  322.  
  323.         getDItem(theDialog, 4, itemType, itemHandle, dispRect);
  324.         SetIText(itemHandle, newDefaults.BriefPath);
  325.  
  326.         getDItem(theDialog, 5, itemType, itemHandle, dispRect);
  327.         SetIText(itemHandle, newDefaults.BriefName);
  328.  
  329.         getDItem(theDialog, 6, itemType, itemHandle, dispRect);
  330.         SetIText(itemHandle, newDefaults.Creator);
  331.  
  332.         for count := 1 to HowManyOmits do
  333.             begin
  334.                 getDItem(theDialog, count + 6, itemType, itemHandle, dispRect);
  335.                 SetIText(itemHandle, ValueToString(newDefaults.IgnoreSess[count]))
  336.             end;
  337.  
  338.         getDItem(theDialog, 21, itemType, itemHandle, dispRect);
  339.         thisButton := ControlHandle(itemHandle);
  340.         if newDefaults.MFinder then
  341.             SetCtlValue(thisButton, 1)
  342.         else
  343.             SetCtlValue(thisButton, 0);
  344.  
  345.         getDItem(theDialog, 22, itemType, itemHandle, dispRect);
  346.         thisButton := ControlHandle(itemHandle);
  347.         if newDefaults.Automatic then
  348.             SetCtlValue(thisButton, 1)
  349.         else
  350.             SetCtlValue(thisButton, 0);
  351.  
  352.         getDItem(theDialog, 23, itemType, itemHandle, dispRect);
  353.         thisButton := ControlHandle(itemHandle);
  354.         if newDefaults.DoBriefRept then
  355.             SetCtlValue(thisButton, 1)
  356.         else
  357.             SetCtlValue(thisButton, 0);
  358.  
  359.         getDItem(theDialog, 31, itemType, itemHandle, dispRect);
  360.         SetIText(itemHandle, StringOf(NewDefaults.SpecialSess : 0));
  361.  
  362.         repeat
  363.             ModalDialog(nil, ItemHit);
  364.  
  365.             case ItemHit of
  366.                 1: { OK button hit, save settings }
  367.                     begin
  368.                         Configure := true;
  369.                         getDItem(theDialog, 3, itemType, itemHandle, dispRect);
  370.                         GetIText(itemHandle, newDefaults.FCLogPath);
  371.                         getDItem(theDialog, 4, itemType, itemHandle, dispRect);
  372.                         GetIText(itemHandle, newDefaults.BriefPath);
  373.                         getDItem(theDialog, 5, itemType, itemHandle, dispRect);
  374.                         GetIText(itemHandle, newDefaults.BriefName);
  375.                         getDItem(theDialog, 6, itemType, itemHandle, dispRect);
  376.                         GetIText(itemHandle, tempString);
  377.                         while length(tempString) < 4 do
  378.                             tempString := concat(tempString, ' ');
  379.                         newDefaults.Creator := copy(tempString, 1, 4);
  380.                         for count := 1 to 12 do
  381.                             begin
  382.                                 getDItem(theDialog, count + 6, itemType, itemHandle, dispRect);
  383.                                 GetIText(itemHandle, tempString);
  384.                                 if length(tempString) > 0 then
  385.                                     newDefaults.IgnoreSess[count] := GetValue(tempString)
  386.                                 else
  387.                                     newDefaults.IgnoreSess[count] := -1
  388.                             end;
  389.                         getDItem(theDialog, 31, itemType, itemHandle, dispRect);
  390.                         GetIText(itemHandle, tempString);
  391.                         StringToNum(tempString, tempLong);
  392.                         newDefaults.SpecialSess := integer(tempLong)
  393.                     end;
  394.  
  395.                 2: 
  396.                     ;  { Cancel button hit—do nothing    }
  397.  
  398.  
  399.                 7..18: 
  400.                     ;
  401.  
  402.                 19: 
  403.                     if ButtonSelected(theDialog, 19) then
  404.                         begin { Look Up Log Path button        }
  405.                             FlashButton(19);
  406.                             InvertRect(dispRect);
  407.                             where.h := 60;
  408.                             where.v := 80;
  409.                             SFPPutFile(where, 'Please select location ', 'test.$', nil, fileReply, 600, nil);
  410.                             if fileReply.good then
  411.                                 begin
  412.                                     Err := Create(fileReply.fname, fileReply.vRefNum, 'QED1', 'TEXT');
  413.                                     MakePath(fileReply.fname, fileReply.vRefNum, Location);
  414.                                     Err := FSDelete(fileReply.fname, fileReply.vRefNum);
  415.                                     getDItem(theDialog, 3, itemType, itemHandle, dispRect);
  416.                                     SetIText(itemHandle, Location)
  417.                                 end;
  418.                             FrameDItem(theDialog, Ok)
  419.                         end;
  420.  
  421.                 20: 
  422.                     if ButtonSelected(theDialog, 20) then
  423.                         begin { Look Up Brief Path button        }
  424.                             FlashButton(20);
  425.                             InvertRect(dispRect);
  426.                             where.h := 60;
  427.                             where.v := 80;
  428.                             SFPPutFile(where, 'Please select location ', 'test.$', nil, fileReply, 600, nil);
  429.                             if fileReply.good then
  430.                                 begin
  431.                                     Err := Create(fileReply.fname, fileReply.vRefNum, 'QED1', 'TEXT');
  432.                                     MakePath(fileReply.fname, fileReply.vRefNum, Location);
  433.                                     Err := FSDelete(fileReply.fname, fileReply.vRefNum);
  434.                                     getDItem(theDialog, 4, itemType, itemHandle, dispRect);
  435.                                     SetIText(itemHandle, Location)
  436.                                 end;
  437.                             FrameDItem(theDialog, Ok)
  438.                         end;
  439.  
  440.                 21: 
  441.                     ToggleButton(newDefaults.MFinder, theDialog, ItemHit);
  442.  
  443.                 22: 
  444.                     ToggleButton(newDefaults.Automatic, theDialog, ItemHit);
  445.  
  446.                 23: 
  447.                     ToggleButton(newDefaults.DoBriefRept, theDialog, ItemHit);
  448.  
  449.                 otherwise
  450.                     ;
  451.             end;{case}
  452.  
  453.         until (ItemHit = 1) | (ItemHit = 2);
  454.  
  455.         DisposDialog(theDialog);
  456.     end;
  457.  
  458. end.